package com.pdf;

import com.itextpdf.text.*;
import com.itextpdf.text.pdf.PdfWriter;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

/**
 * 页面大小,页面背景色,页边空白,Title,Author,Subject,Keywords
 *
 * @author liyiruo
 * @Description
 * @Date 2021/8/10 下午3:57
 */
public class RectanglePDF {
    public static void main(String[] args) throws DocumentException, FileNotFoundException {
        //页面大小
        Rectangle rect = new Rectangle(PageSize.B5.rotate());
        //页面背景色
        rect.setBackgroundColor(BaseColor.ORANGE);
        Document doc = new Document(rect);
        PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(DemoPDF.path + "RectanglePDF.pdf"));
        //PDF版本(默认1.4)
        writer.setPdfVersion(PdfWriter.PDF_VERSION_1_2);
        //文档属性
        doc.addTitle("Title@liyiruo");
        doc.addAuthor("Author@liyiruo");
        doc.addSubject("Subject@liyiruo");
        doc.addKeywords("Keywords@liyiruo");
        doc.addCreator("Creator@liyiruo");
        //页边空白
        doc.setMargins(10, 20, 30, 40);
        doc.open();
        doc.add(new Paragraph("RectanglePDF"));
        doc.close();
    }
}
